chcp 65001

@echo off


set "SevenZip_DOWNLOAD_URL=http://39.105.231.80:9900/7z2409-x64.exe"
set "SevenZip_INSTALLER=C:\Temp\7z2409-x64.exe"

set "JAVA_DOWNLOAD_URL=https://repo.huaweicloud.com/java/jdk/8u181-b13/jdk-8u181-windows-x64.exe"
set "JAVA_INSTALLER=C:\Temp\jdk-8u181-windows-x64.exe"
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181"

set "NODE_DOWNLOAD_URL=https://nodejs.org/dist/v18.20.3/node-v18.20.3-x64.msi"
set "NODE_INSTALLER=C:\Temp\node-v18.20.3-x64.msi"

set "REDIS_DOWNLOAD_URL=http://39.105.231.80:9900/Redis-x64-5.0.14.1.msi"
set "REDIS_INSTALLER=C:\Temp\Redis-x64-5.0.14.1.msi"
set "REDIS_EXE_PATH=C:\Program Files\Redis"

set "NVM_DOWNLOAD_URL=http://39.105.231.80:9900/nvm-setup.exe"
set "NVM_INSTALLER=C:\Temp\nvm-setup.exe"

set "MVN_DOWNLOAD_URL=http://39.105.231.80:9900/apache-maven-3.6.3.zip"
set "MVN_INSTALLER=C:\Temp\apache-maven-3.6.3.zip"
set "MVN_TARGET=C:\"
set "MVN_HOME=C:\apache-maven-3.6.3"


set "IDEA_DOWNLOAD_URL=https://download.jetbrains.com/idea/ideaIU-2022.2.5.exe"
set "IDEA_INSTALLER=C:\Temp\ideaIU-2022.2.5.exe"
set "IDEA_EXE_PATH=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2022.2.5\bin\idea64.exe"
set "IDEA_LINK_NAME=IntelliJ IDEA"
set "IDEA_POJIE_URL=http://39.105.231.80:9900/idea.zip"
set "IDEA_POJIE_INSTALLER=C:\Temp\idea.zip"
set "IDEA_DOWNLOAD_TIP_URL=http://39.105.231.80:9900/idea安装后怎么破解.txt"
set "IDEA_INSTALLER_TIP=C:\Temp\idea安装后怎么破解.txt"

set DESKTOP_PATH="%USERPROFILE%\Desktop"

set "VSCODE_DOWNLOAD_URL=https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user"
set "VSCODE_INSTALLER=C:\Temp\vscodeSetup.exe"
set "VSCODE_EXE_PATH=C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\Code.exe"

set "GIT_DOWNLOAD_URL=https://registry.npmmirror.com/-/binary/git-for-windows/v2.47.1.windows.1/Git-2.47.1-64-bit.exe"
set "GIT_INSTALLER=C:\Temp\Git-2.47.1-64-bit.exe"

set "NOTEPADPP_DOWNLOAD_URL=http://39.105.231.80:9900/npp.8.5.2.Installer.x64.exe"
set "NOTEPADPP_INSTALLER=C:\Temp\npp.8.5.2.Installer.x64.exe"

set "DBEVER_DOWNLOAD_URL=https://mirrors.tuna.tsinghua.edu.cn/github-release/dbeaver/dbeaver/LatestRelease/dbeaver-ce-24.3.0-x86_64-setup.exe"
set "DBEVER_INSTALLER=C:\Temp\dbeaver-ce-24.3.0-x86_64-setup.exe"




set "CHROME_DOWNLOAD_URL=http://39.105.231.80:9900/ChromeSetup.exe"
set "CHROME_INSTALLER=C:\Temp\ChromeSetup.exe"
set "CHROME_INSTALLER_TIP=C:\Temp\谷歌Chrome浏览器崩溃解决方法.txt"
set "CHROME_DOWNLOAD_TIP_URL=http://39.105.231.80:9900/谷歌Chrome浏览器崩溃解决方法.txt"

set "HBUILDER_DOWNLOAD_URL=http://39.105.231.80:9900/HBuilderX.4.56.zip"
set "HBUILDER_INSTALLER=C:\Temp\HBuilderX.4.56.zip"
set "HBUILDER_INSTALL_DIR=C:\Program Files"

set "FILEZILLA_DOWNLOAD_URL=http://39.105.231.80:9900/FileZilla_3.68.1_win64-setup.exe"
set "FILEZILLA_INSTALLER=C:\Temp\FileZilla_3.68.1_win64-setup.exe"
:: 初始化变量来跟踪用户的选择


set "install_java="
set "install_node="
set "install_redis="

set "install_git="

set "install_mvn="
set "install_idea="
set "install_vscode="

set "install_nvm="

set "install_notepadpp="
set "install_dbever="
set "install_chrome="
set "install_hbuilder="
set "install_filezilla="
:: 询问用户是否要安装每个软件

echo 你想要安装哪些软件？
echo a) java
echo b) node
echo c) redis
echo d) git
echo e) mvn
echo f) idea
echo g) vscode
echo h) nvm
echo i) notepadpp
echo j) dbever
echo k) chrome
echo l) hbuilder
echo m) filezilla
echo 请输入你想要安装的软件的字母（多个字母之间用空格分隔，输入all全部安装）: 
set /p "user_input="

:: 分析用户输入

for %%i in (%user_input%) do (
    if /i "%%i"=="a" set "install_java=yes"
    if /i "%%i"=="b" set "install_node=yes"
    if /i "%%i"=="c" set "install_redis=yes"
    if /i "%%i"=="d" set "install_git=yes"
	if /i "%%i"=="e" set "install_mvn=yes"
	if /i "%%i"=="f" set "install_idea=yes"
	if /i "%%i"=="g" set "install_vscode=yes"
	if /i "%%i"=="h" set "install_nvm=yes"
	if /i "%%i"=="i" set "install_notepadpp=yes"
	if /i "%%i"=="j" set "install_dbever=yes"
	if /i "%%i"=="k" set "install_chrome=yes"
	if /i "%%i"=="l" set "install_hbuilder=yes"
	if /i "%%i"=="m" set "install_filezilla=yes"
)


if "%user_input%" == "all" (


	 set "install_java=yes"
     set "install_node=yes"
     set "install_redis=yes"
     set "install_git=yes"
	 set "install_mvn=yes"
	 set "install_idea=yes"
	 set "install_vscode=yes"
	 set "install_nvm=yes"
	 set "install_notepadpp=yes"
	 set "install_dbever=yes"
	 set "install_chrome=yes"
	 set "install_hbuilder=yes"
	 set "install_filezilla=yes"
)
:: 装个7z

set "SevenZip=C:\Program Files\7-Zip\7z.exe"

if exist "%SevenZip%" (
	echo 7zexist
) else (
	curl  -o "%SevenZip_INSTALLER%" "%SevenZip_DOWNLOAD_URL%"
	%SevenZip_INSTALLER% /S
)

if not exist "C:\Temp" mkdir "C:\Temp"

:: 根据用户的选择执行安装操作（这里用echo代替实际的安装命令）

if defined install_java (


    echo 安装java开始------------------------------------------------------------------------------------------------
	
	REM 设置下载地址和安装文件路径


	 
	REM 使用 curl 下载 JDK 安装包

	echo [1/4]正在下载 JDK 安装包，源:%JAVA_DOWNLOAD_URL%

	curl  -o "%JAVA_INSTALLER%" "%JAVA_DOWNLOAD_URL%"
	if %errorlevel% neq 0 (
		echo 下载失败！
		exit /b %errorlevel%
	) else (
	   echo 下载 JDK 安装包成功！
	)
	 
	REM 安装 JDK（静默安装，具体参数需参考安装程序的文档）

	echo [2/4]正在安装 JDK...，盘符:%JAVA_HOME%
	%JAVA_INSTALLER% /s INSTALLDIR="%JAVA_HOME%" /L C:\Temp\install.log
	if %errorlevel% neq 0 (
		echo 安装失败！查看 C:\Temp\install.log 以获取更多信息。
		exit /b %errorlevel%
	)
	 
	REM 配置环境变量（需要管理员权限）

	echo [3/4]配置环境变量...
	setx  /m JAVA_HOME "%JAVA_HOME%" >NUL

	REM 这里害怕有的电脑path，已经很大了。但是setx函数会强制截取前1024字符

	setx /m PATH "%JAVA_HOME%\bin;%PATH%"

	REM 验证安装

	REM echo [4/5]验证Java安装,执行java -version...
	
	REM java -version
	
	REM if %errorlevel% neq 0 (
	REM	echo Java环境变量配置失败或 Java 未正确安装！
	REM	exit /b %errorlevel%
	REM )
	

	REM 清理临时文件

	REM echo [5/5]清理临时文件...
	
	REM del "%JAVA_INSTALLER%"
	
	del C:\Temp\install.log

	echo [4/4]Java 已成功安装并配置！

	echo 安装java结束------------------------------------------------------------------------------------------------

)

if defined install_node (
	echo 安装Node开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载NODE安装包，源:%NODE_DOWNLOAD_URL%
	
	REM 使用curl下载Node.js安装程序
	
    curl -o "%NODE_INSTALLER%" "%NODE_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载NODE安装包失败！
		exit /b %errorlevel%
	) else (
	   echo 下载NODE安装包成功！
	)
	
    REM 检查下载是否成功
    if exist "%NODE_INSTALLER%" (
	
        REM 静默安装Node.js
		
		echo [2/3]正在安装NODE...
		
        msiexec /i "%NODE_INSTALLER%" /quiet /norestart
		
        if %errorlevel% neq 0 (
			echo 安装失败！
			exit /b %errorlevel%
		)
		
		echo [3/3]Node.js安装完成!
		
		REM  (node -v  2>&1) && (
		REM 	echo [4/4]验证通过，Node.js安装完成!
		REM  ) || (
		REM 	echo node 未安装或未正确配置。
		REM  )

		REM  echo 安装Node结束------------------------------------------------------------------------------------------------
		
        REM 可选：安装成功后删除安装程序
        REM del "%NODE_INSTALLER%"
        
    ) else (
        echo 下载Node.js安装程序失败。
    )
)


if defined install_redis (
	echo 安装Redis开始------------------------------------------------------------------------------------------------
	
	echo [1/4]正在下载Redis安装包，源:%REDIS_DOWNLOAD_URL%
	
	REM 使用curl下载Redis安装程序
	
    curl -o "%REDIS_INSTALLER%" "%REDIS_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载Redis安装包失败！
		pause
		exit /b %errorlevel%
	) else (
	   echo 下载Redis安装包成功！
	)
	
    REM 检查下载是否成功
    if exist "%REDIS_INSTALLER%" (
	
        REM 静默安装Redis
		
		echo [2/4]正在安装Redis...
		
        msiexec /i "%REDIS_INSTALLER%" /QN

        if %errorlevel% neq 0 (
			echo 安装失败！
			pause
			exit /b %errorlevel%
		)
		
		echo [3/4]验证Redis安装...
		REM redis -v
		if %errorlevel% neq 0 (
			echo redis未正确安装！
			pause
			exit /b %errorlevel%
		)
		echo [4/4]验证通过，redis安装完成! 位置:%REDIS_EXE_PATH%
		
		REM setx /m PATH "%REDIS_EXE_PATH%;%PATH%"
		
		
		REM start "测试redis" cmd /c redis-server.exe "C:\Program Files\Redis\redis.windows.conf"


		echo 安装redis结束------------------------------------------------------------------------------------------------
		
    ) else (
        echo 下载redis安装程序失败。
    )
)




if defined install_git (
	echo 安装git开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载git安装包，源:%GIT_DOWNLOAD_URL%
	
	REM 使用curl下载git安装程序
    curl --insecure -L -o "%GIT_INSTALLER%" "%GIT_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载git安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载git安装包成功！
	)
	
	if exist "%GIT_INSTALLER%" (
		echo [3/3]git安装成功！
		%GIT_INSTALLER% /SILENT /NORESTART /NOCANCEL /SP- /VERYSILENT
	) else (
		echo git安装失败！
	)
	
	echo 安装git结束------------------------------------------------------------------------------------------------
)


if defined install_mvn (
	echo 安装maven开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载mvn安装包，源:%MVN_DOWNLOAD_URL%
	
	REM 使用curl下载mvn安装程序
	
    curl -o "%MVN_INSTALLER%" "%MVN_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载mvn安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载mvn安装包成功！
	)
	
	if not exist "%MVN_HOME%" (
		mkdir "%MVN_HOME%"
	) 
	
    REM 检查下载是否成功
	
    if exist "%MVN_INSTALLER%" (
		"%SevenZip%" x "%MVN_INSTALLER%" -o"%MVN_TARGET%"
			setx  /m MAVEN_HOME "%MVN_HOME%" >NUL
			setx /m PATH "%MVN_HOME%\bin;%PATH%"
			echo [3/3]配置环境变量成功！
    ) else (
        echo 下载MVN安装程序失败。
    )
	echo 安装MAVEN结束------------------------------------------------------------------------------------------------
)
	

if defined install_idea (

	echo 安装IDEA开始------------------------------------------------------------------------------------------------
	
	
	echo [1/4]正在下载IDEA安装包，源:%IDEA_DOWNLOAD_URL%

	REM 使用curl下载IDEA安装程序
    curl --insecure -L  -o "%IDEA_INSTALLER%" "%IDEA_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载IDEA安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/4]下载IDEA安装包成功,安装中...
	)
	
	if exist "%IDEA_INSTALLER%" (
		%IDEA_INSTALLER% /S
		echo [3/4]IDEA安装成功！
	
	) else (
		echo IDEA安装失败！
	)

	REM 设置变量

	
	
	mklink IntelliJIDEA64.exe "%IDEA_EXE_PATH%"
	
	REM IntelliJIDEA64.exe
	
	curl -o "%IDEA_POJIE_INSTALLER%" "http://39.105.231.80:9900/idea.zip"
	curl -o "%IDEA_INSTALLER_TIP%" "%IDEA_DOWNLOAD_TIP_URL%"
	mkdir "C:\Temp\ideapojie"
	
	if exist "%IDEA_POJIE_INSTALLER%" (
		"%SevenZip%" x "%IDEA_POJIE_INSTALLER%" -o"C:\Temp\ideapojie"
		
		REM "C:\Temp\ideapojie\IDEA激活.vbs"
		
		echo [4/4]idea激活完成！
	) else (
		echo idea激活失败！
	)
	
	echo 安装idea结束------------------------------------------------------------------------------------------------
)

if defined install_vscode (
	echo 安装vscode开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载vscode安装包，源:%VSCODE_DOWNLOAD_URL%
	
	REM 使用curl下载IDEA安装程序
    curl --insecure -L  -o "%VSCODE_INSTALLER%" "%VSCODE_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载vscode安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载vscode安装包成功！
	)
	
	if exist "%VSCODE_INSTALLER%" (
		echo [3/3]vscode安装成功！
		%VSCODE_INSTALLER% /silent
	) else (
		echo vscode安装失败！
	)
	
	mklink VSCode.exe "%VSCODE_EXE_PATH%"
	
	echo 安装vscode结束------------------------------------------------------------------------------------------------
)


if defined install_nvm (
	echo 安装nvm开始------------------------------------------------------------------------------------------------
	
	echo [1/4]正在下载nvm安装包，源:%NVM_DOWNLOAD_URL%
	
	REM 使用curl下载nvm安装程序
	
    curl -o "%NVM_INSTALLER%" "%NVM_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载nvm安装包失败！
		exit /b %errorlevel%
	) else (
	   echo 下载nvm安装包成功！
	)
	
    REM 检查下载是否成功
    if exist "%NVM_INSTALLER%" (
	
        REM 静默安装nvm
		
		echo [2/4]正在安装nvm...
		
		%NVM_INSTALLER% /S
		
		if exist "C:\Users\Administrator\AppData\Roaming\nvm\nvm.exe" (
			echo 安装成功
			
			echo [3/4]验证nvm安装,执行nvm -v...
			
			echo [4/4]修改nvm镜像...


			echo node_mirror=https://npmmirror.com/mirrors/node/ >> "C:\Users\Administrator\AppData\Roaming\nvm\settings.txt"
			
			echo npm_mirror=https://npmmirror.com/mirrors/npm/ >> "C:\Users\Administrator\AppData\Roaming\nvm\settings.txt"
			
		) else (
			echo 安装失败！
			
		)
		
		REM start "修改nvm镜像" cmd /c nvm -v && nvm node_mirror  https://npmmirror.com/mirrors/node/ && nvm npm_mirror  https://npmmirror.com/mirrors/npm/ && pause
		
		
		echo 安装nvm结束------------------------------------------------------------------------------------------------
		
    ) else (
        echo 下载nvm安装程序失败。
    )
)


if defined install_notepadpp (
	echo 安装notepadpp开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载notepadpp安装包，源:%NOTEPADPP_DOWNLOAD_URL%
	
	REM 使用curl下载notepadpp安装程序
    curl --insecure -L -o "%NOTEPADPP_INSTALLER%" "%NOTEPADPP_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载notepadpp安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载notepadpp安装包成功！
	)
	
	if exist "%NOTEPADPP_INSTALLER%" (
		echo [3/3]notepadpp安装成功！
		start %NOTEPADPP_INSTALLER% /quiet
	) else (
		echo notepadpp安装失败！
	)
	
	echo 安装notepadpp结束------------------------------------------------------------------------------------------------
)

if defined install_dbever (
	echo 安装dbever开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载dbever安装包，源:%DBEVER_DOWNLOAD_URL%
	
	REM 使用curl下载dbever安装程序
    curl --insecure -L -o "%DBEVER_INSTALLER%" "%DBEVER_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载dbever安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载dbever安装包成功！
	)
	
	if exist "%DBEVER_INSTALLER%" (
		%DBEVER_INSTALLER% /S222
		if %errorlevel% neq 0 (
			echo 安装DBEVER失败！
			exit /b %errorlevel%
		)
		echo [3/3]dbever安装成功！
		
	) else (
		echo dbever安装失败！
	)
	
	echo 安装dbever结束------------------------------------------------------------------------------------------------
)
if defined install_chrome (
	echo 安装chrome开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载chrome安装包，源:%CHROME_DOWNLOAD_URL%
	
	REM 使用curl下载chrome安装程序
    curl --insecure -L -o "%CHROME_INSTALLER%" "%CHROME_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载chrome安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载chrome安装包成功！
	)
	
	if exist "%CHROME_INSTALLER%" (
		%CHROME_INSTALLER% 
		if %errorlevel% neq 0 (
			echo 安装chrome失败！
			exit /b %errorlevel%
		)
		echo [3/3]chrome安装成功！
		
	) else (
		echo chrome安装失败！
	)
	
	curl -o "%CHROME_INSTALLER_TIP%" "%CHROME_DOWNLOAD_TIP_URL%"
	echo 安装chrome结束------------------------------------------------------------------------------------------------
)
if defined install_hbuilder (
	echo 安装hbuilder开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载hbuilder安装包，源:%HBUILDER_DOWNLOAD_URL%
	
	REM 使用curl下载chrome安装程序
    REM curl -o "%HBUILDER_INSTALLER%" "%HBUILDER_DOWNLOAD_URL%"
	
    if %errorlevel% neq 0 (
		echo 下载hbuilder安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载hbuilder安装包成功！
	)
	
	if exist "%HBUILDER_INSTALLER%" (
		"%SevenZip%" x "%HBUILDER_INSTALLER%" -o"%HBUILDER_INSTALL_DIR%"
		mklink HBuilderX.exe "%HBUILDER_INSTALL_DIR%/HBuilderX/HBuilderX.exe"
		if %errorlevel% neq 0 (
			echo 安装hbuilder失败！
			exit /b %errorlevel%
		)
		echo [3/3]hbuilder安装成功！
		
	) else (
		echo hbuilder安装失败！
	)
	
	echo 安装hbuilder结束------------------------------------------------------------------------------------------------
)
if defined install_filezilla (
	echo 安装filezilla开始------------------------------------------------------------------------------------------------
	
	echo [1/3]正在下载filezilla安装包，源:%FILEZILLA_DOWNLOAD_URL%
	
	REM 使用curl下载filezilla安装程序
    curl --insecure -L -o "%FILEZILLA_INSTALLER%" "%FILEZILLA_DOWNLOAD_URL%"
    if %errorlevel% neq 0 (
		echo 下载filezilla安装包失败！
		exit /b %errorlevel%
	) else (
	   echo [2/3]下载filezilla安装包成功！
	)
	
	if exist "%FILEZILLA_INSTALLER%" (
		%FILEZILLA_INSTALLER% 
		if %errorlevel% neq 0 (
			echo 安装filezilla失败！
			exit /b %errorlevel%
		)
		echo [3/3]filezilla安装成功！
		
	) else (
		echo filezilla安装失败！
	)
	
	echo 安装filezilla结束------------------------------------------------------------------------------------------------
)
pause